package com.cn;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.task.api.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 创建文件方式
 */
@SpringBootTest
public class flowableTest05 {

    @Autowired
    private ProcessEngine processEngine;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;


    /**
     * 创建流程引擎的方式
     * ACT REDEPLOYMENT 是否创建成功
     */
    @Test
    void createProcess(){
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("process01-基础/流程引擎01.bpmn20.xml")
                .name("流程引擎02")
                .deploy();
        System.out.println("deploy.getId()="+deploy.getId());
    }

    /**\
     * 创建任务启动
     */
    @Test
    void startRun(){
        String id = "流程引擎01:3:28c2557f-b084-11ee-95a0-30d04231d1ff";
        Map<String,Object> map = new HashMap<>();
        map.put("assgin","站桑");
        runtimeService.startProcessInstanceById(id,map);
    }

    /**
     * 任务完成代办任务的方式
     */
    @Test
    void startTask(){
     String taskId = "b0713423-b082-11ee-bad6-30d04231d1ff";
     taskService.complete(taskId);
    }

    /**
     * 根据用户名称查询待办的方式
     */
    @Test
    void findTask(){
        List<Task> list = taskService.createTaskQuery()
                .taskName("经理")
                .list();
        for (Task task : list) {
            System.out.println("task.getId()"+task.getId());
        }
    }
}